import request from '@/config/axios'
import { Sku, Spu } from '@/api/mall/product/spu'

export interface PointsActivityVO {
  id?: number
  name?: string
  des?: string
  spuId?: number
  startTime?: Date
  endTime?: Date
  status?: number
  activityType?: number
  imgUrl: string // 图片
  detailImgUrl: string // 图片
  productsList: PointsProductVO[]
}

// 积分活动所需属性
export interface PointsProductVO {
  spuId: number
  skuId: number
  combinationPrice: number // 积分价格
  points: number // 积分
}

// 扩展 Sku 配置
export type SkuExtension = Sku & {
  productConfig: PointsProductVO
}

export interface SpuExtension extends Spu {
  skus: SkuExtension[] // 重写类型
}

// 查询积分活动列表
export const getPointsActivityPage = async (params) => {
  return await request.get({ url: '/promotion/points-activity/page', params })
}

// 查询积分活动详情
export const getPointsActivity = async (id: number) => {
  return await request.get({ url: '/promotion/points-activity/get?id=' + id })
}

// 新增积分活动
export const createPointsActivity = async (data: PointsActivityVO) => {
  return await request.post({ url: '/promotion/points-activity/create', data })
}

// 修改积分活动
export const updatePointsActivity = async (data: PointsActivityVO) => {
  return await request.put({ url: '/promotion/points-activity/update', data })
}

// 关闭积分活动
export const closePointsActivity = async (id: number) => {
  return await request.put({ url: '/promotion/points-activity/close?id=' + id })
}

// 删除积分活动
export const deletePointsActivity = async (id: number) => {
  return await request.delete({ url: '/promotion/points-activity/delete?id=' + id })
}

// 查询积分活动列表
export const pointsList = async (params) => {
  return await request.get({ url: '/promotion/points-activity/pointsList', params })
}
